<!DOCTYPE html>
<html lang="en">
	<head>
		<meta charset="UTF-8">
		<title>Document</title>
	</head>
	<body>
		
	</body>
</html>
<script>
	// 继承
	// ES6之前, 大家可以理解为js的继承是别人的东西拿来用就是继承
	// js把重点放在了对象上, 弱化了类的概念, js认为继承于同一(原型)对象的对象属于同一个类

	console.log(typeof {});

	var person = {
		name: "小明",
		age: "28",
		gender: "男",
		say: function() {
			console.log(this.name, this.age);
		}
	}

	var animal = {
		type: "猫科",
		color: "花"
	};

	// 简单的继承函数
	function inherit(obj) {
		if (typeof obj != "object") return {};
		var p = {};
		for (var key in obj) {
			p[key] = obj[key];
			console.log("p[" + key + "]=obj[" + key + "]");
		}
		// p["name"] = obj["name"];
		// p["age"] = obj["age"];
		// p["gender"] = obj["gender"];
		// p["say"] = obj["say"];
		// p["type"] = obj["type"];
		// p["color"] = obj["color"];
		return p;
	}

	// var p = inherit(person);
	// console.log(p);
	// var cat = inherit(animal);
	// console.log(cat);

	// Zombie.call({name: "waige"}, "xiaoming");


	function Zombie(name) {
		console.log(this);
		this.name = name;
		this.run = function() {
			console.log("我会走");
		};
	}

	function ZombieOfHat(name, color) {

		// 通过call和apply实现继承
		// Zombie.call(this, name);
		Zombie.apply(this, [name]);

		this.color = color;
		this.hasHat = true;
		this.info = function() {
			console.log("抗揍");
		};


	} 

	var z1 = new ZombieOfHat("DJ", "绿色");
	console.log(z1);


	// 构造函数都有一个prototype属性
	console.log(Person.prototype);
	Person.prototype.gender = "男";
	function Person(name, age) {
		// console.log(this);
		this.name = name;
		this.age = age;
	}
	var p1 = new Person("徐旺", 38);
	// 构造函数(Person)的原型属性(prototype)拥有的方法和属性都会被构造出来的对象继承
	console.log(p1);
	console.log(p1.gender);

	function Student(name, age, score) {
		this.score = score;
		// this.a = 26;
		// this.b = "00";
		Person.call(this, name, age);
	}
	Student.prototype = Person.prototype;
	var stu = new Student("小明", 22, 90);
	// 第一步: name = "小明", age = 22, score = 90;
	// this.score = 90;
	// name = "小明", age = 22
	// this.name = "小明"
	// this.age = 22
	// return this;
	// stu继承于 Student.prototype
	// 原型继承
	
	console.log(stu);
	console.log(stu.gender);


	// var arr = {
	// 	0: 1,
	// 	1: 2,
	// 	length: 2
	// };
	// [].slice.call(arr).forEach(function(index, e) {
	// 	console.log(index, e);
	// });

	







</script>